using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace Universe.Farm
{
    [Serializable]
    public class ServicesScope
    {
        public static readonly string AnyName = string.Empty;

        public static ServicesScope FullScope
        {
            get
            {
                ServicesScope ret = new ServicesScope();
                ret.IsFullScope = true;
                return ret;
            }
        }

        public static ServicesScope Empty
        {
            get { return new ServicesScope(); }
        }
        

        private bool _IsFullScope = false;
        private List<Item> _items = new List<Item>();


        public bool IsFullScope
        {
            get { return _IsFullScope; }
            set { _IsFullScope = value; }
        }

        [XmlArray("Items"), XmlArrayItem("Item", typeof(Item))]
        public List<Item> Items
        {
            get { return _items; }
            set { _items = value; }
        }

        [Serializable]
        public class Item
        {
            private string _Computer;
            private string _ServiceName;

            public Item()
            {
            }

            public Item(string computer, string serviceName)
            {
                _Computer = computer;
                _ServiceName = serviceName;
            }


            public string ServiceName
            {
                get { return _ServiceName; }
                set { _ServiceName = value; }
            }

            public string Computer
            {
                get { return _Computer; }
                set { _Computer = value; }
            }

            public bool IsAnyComputer
            {
                get { return string.IsNullOrEmpty(Computer); }
            }

            public bool IsAnyService
            {
                get { return string.IsNullOrEmpty(ServiceName); }
            }
        }

        public ServicesScope AddComputer(string computerName)
        {
            Item item = new Item(computerName, AnyName);
            _items.Add(item);
            return this;
        }

        public ServicesScope AddService(string serviceName)
        {
            Item item = new Item(AnyName, serviceName);
            _items.Add(item);
            return this;
        }

        public ServicesScope Add(string computerName, string serviceName)
        {
            Item item = new Item(computerName, serviceName);
            _items.Add(item);
            return this;
        }

    }
}